#!/usr/bin/python

import roslib; roslib.load_manifest('brain_stuff')
import rospy
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import smach


class Interface(smach.State):
   def __init__(self):
      # Smach
      smach.State.__init__(self, outcomes=['success', 'aborted'])
   
      # Pyside
      self.label = QLabel()
      self.group = QGroupBox('group1')
      label2 = QLabel()
      label2.setText('Hello World')
      vbox = QVBoxLayout()
      vbox.addWidget(label2)
      self.group.setLayout(vbox)


   def execute(self, userdata):
      try:
         self.group.show()
         app.exec_()
      except KeyboardInterrupt:
         app.quit()
         return 'aborted'
      app.quit()
      return 'success' 

   def showImage(self):
      rospy.loginfo("showImage")
      #label = QLabel()
      #label2 = QLabel()
      #label2.setText('Hello World')

      #vbox = QVBoxLayout()

      #qimage = IplQImage(self.cv_image)
      #qpixmap = QPixmap.fromImage(qimage)
      #label.setPixmap(qpixmap)

      #vbox.addWidget(label2)
      #vbox.addWidget(label)

      #self.group.setLayout(vbox)
      #self.setGeometry(0,0,self.cv_image.width, self.cv_image.height)
      

if __name__== "__main__":
   rospy.init_node('brain_interface', log_level=rospy.DEBUG)

   app = QApplication(sys.argv)
   machine = smach.StateMachine(outcomes = ['success'])
   with machine:
      smach.StateMachine.add("Interface", Interface(), transitions={'aborted':'success', 'success':'Interface'})
   try:
      machine.execute()
   except KeyboardInterrupt:
      exit()







